#include <iostream>

bool Find(int ** matrix, int rows, int cols, int number);

int main(int argc, char * argv[])
{
    const int rows = 5, cols = 5;
    // 动态开辟空间
    int ** pMatrix = new int * [rows];
    for(int i = 0; i < rows; ++i)
        pMatrix[i] = new int [cols];

    for(int i = 0; i < rows; ++i)
        for(int j = 0; j < cols; ++j)
        {
            pMatrix[i][j] = i * rows + j;
            std::cout << i * rows + j << std::endl;
        }

    bool isFind = Find(pMatrix, rows, cols, 11);
    std::cout << isFind << std::endl;

    // 释放开辟的资源
    for(int i = 0; i < rows; ++i)
        delete [] pMatrix[i];
    delete [] pMatrix;
}

bool Find(int ** matrix, int rows, int cols, int number)
{
    bool found = false;
    if (matrix != NULL && rows > 0 && cols > 0)
    {
        int row = 0;
        int col = cols - 1;
        while (row < rows && col >= 0)
        {
            if (matrix[row][col] == number)
            {
                std::cout << "(row, col) = " << "(" << row << ", " << col << ")" << std::endl;
                found = true;
                break;
            }
            else if(matrix[row][col] > number)
                --col;
            else
                ++row;
        }
    }
    return found;
}
